package com.hdu.controller.collegeManagement;


import cn.hutool.core.bean.BeanUtil;
import com.hdu.pojo.PageBean;
import com.hdu.pojo.Result;
import com.hdu.service.IMajorService;
import com.hdu.vo.MajorList;
import com.hdu.vo.MajorView;
import com.hdu.vo.RankTable;
import com.hdu.vo.SchoolList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 专业实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2023-10-28
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "专业管理接口")
@RequestMapping("/major")
public class MajorController {

    private final IMajorService majorService;

    @ApiOperation("分页获取专业列表")
    @GetMapping("/page")
    public Result<PageBean<MajorList>> page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       String level, String kind, String type, String order, String name) {
        log.info("分页获取专业列表, 参数: {},{},{},{},{},{},{}", page, limit, level, kind, type, order, name);
        PageBean<MajorList> pageBean = majorService.majorPage(page, limit, level, kind, type, order, name);
        return Result.success(pageBean);
    }

    @ApiOperation("获取专业概述")
    @GetMapping("/overview/{id}")
    public Result<?> overview(@PathVariable String id) {
        log.info("获取专业概述, id: {}", id);
        return Result.success(BeanUtil.copyProperties(majorService.getById(id), MajorView.class));
    }

    @ApiOperation("获取专业导航")
    @GetMapping("/nav")
    public Result<?> navigation() {
        return Result.success(majorService.navigation());
    }

    @ApiOperation("获取开设专业学校分数线")
    @GetMapping("/rank")
    public Result<PageBean<RankTable>> score(@RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer limit,
                        String name, Integer region, String year, Integer type, Integer batch,
                        String level, String special, String mold, String province) {
        log.info("分页获取开设专业学校分数线, 参数: {},{},{},{},{},{},{},{},{},{}", page, limit, name, batch, type, year, level, special, mold, province);
        PageBean<RankTable> pageBean = majorService.rank(page, limit, name, region, batch, type, year, level, special, mold, province);
        return Result.success(pageBean);
    }

    @ApiOperation("获取开设专业学校分数线导航")
    @GetMapping("/rank/{name}/{region}/{year}")
    public Result<?> score(@PathVariable String name, @PathVariable Integer region, @PathVariable String year) {
        log.info("获取开设专业学校分数线导航, 参数: {},{},{}", name, region, year);
        return Result.success(majorService.rankSelect(name, region, year));
    }

    @ApiOperation("获取开设专业学校软科排行")
    @GetMapping("/ruan")
    public Result<PageBean<SchoolList>> ruan(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       Integer id, String level, String special, String type, String region) {
        log.info("获取开设专业学校分数线导航, 参数: {},{},{},{},{},{},{}", page, limit, id, level, special, type, region);
        PageBean<SchoolList> pageBean = majorService.schoolPage(page, limit, id, level, region, type, special);
        return Result.success(pageBean);
    }
}
